package com.haierp.controller;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.haierp.dto.TaskDailyDTO;
import com.haierp.model.TaskDailyDetail;
import com.haierp.model.WxSession;
import com.haierp.service.ITaskDailyDetailService;
import com.haierp.service.ITaskDailyService;
import com.haierp.service.IWxSessionService;
import com.haierp.util.JsonPageResult;
import com.haierp.vo.TaskDailyVO;
import com.wangzhixuan.commons.base.BaseController;


@Controller
@RequestMapping("/wx")
public class WxTaskController extends BaseController {

	@Autowired
	private ITaskDailyDetailService iTaskDailyDetailService;
	@Autowired
	private ITaskDailyService iTaskDailyService;

	@Autowired
	private IWxSessionService wxSessionService;
	
	
	/**
	 *
	 * @param
	 * @return
	 */
	@RequestMapping("/getTaskDaily")
	@ResponseBody
	public Object getTaskDaily(Long userId,String cookie,Long taskId) {
		JsonPageResult<List<TaskDailyVO>> result = new JsonPageResult<>();
		Map<String,WxSession> maps = wxSessionService.getMaps();
		if(StringUtils.isNotEmpty(cookie)&&maps.containsKey(cookie))
		{
			TaskDailyDetail taskDailyDetail = new TaskDailyDetail();
			taskDailyDetail.setTaskId(taskId);
			taskDailyDetail.setBuyerId(userId);
			
			EntityWrapper<TaskDailyDetail> wrapper = new EntityWrapper<TaskDailyDetail>();
			wrapper.where("status={0}", "0");
			
			
//			EntityWrapper<Category> wrapper = new EntityWrapper<Category>();
//			wrapper.orderBy("seq");
//			wrapper.where("status={0}", "0");
//			List<Category> categories =categoryMapper.selectList(wrapper);
			
			List<TaskDailyDetail> taskList = null;//iTaskDailyDetailService.selectList(taskDailyDetail);
			
			if(taskList != null){
				
				
			}
			
			
		}
		return result.buildIsSuccess(true);
		
	}
	
	
	@RequestMapping("/getTaskList")
	@ResponseBody
	public Object getTaskList(Long userId,String cookie,Integer pageNo) {
		JsonPageResult<List<TaskDailyVO>> result = new JsonPageResult<>();
		Map<String,WxSession> maps = wxSessionService.getMaps();
		if(StringUtils.isNotEmpty(cookie)&&maps.containsKey(cookie))
		{
			TaskDailyDTO taskDailyDTO = new TaskDailyDTO();
			taskDailyDTO.setWxUserId(userId);
			taskDailyDTO.setPageIndex(pageNo);
			int count = iTaskDailyService.queryTaskCount(taskDailyDTO);
			result.buildPage(count, taskDailyDTO);
			if(count>0){
				List<TaskDailyVO> taskDailyList= iTaskDailyService.queryTaskDaily(taskDailyDTO);
				result.buildData(taskDailyList);
			}
			
		}
		return result.buildIsSuccess(true);
		
	}
	
}
